<? $page_title='管理仓库' ?>
<? include "FASHION/page_header.phtml" ?>

<table border="0" id="list" class="list"><tbody>
<tr>
	<th>名称</th>
	<th>位置</th>
	<th>备注</th>
	<th>操作</th>
</tr>
<? if($list)foreach($list as $u){ ?>
<tr warehouse_id="<?$u.id?>">
	<td><?$u.name?></td>
	<td><?$u.location?></td>
	<td><?$u.remark?></td>
	<td>
		<a href="javascript:;" onclick="modify('<?$u.id?>')" class="modify" title="修改"></a>
		<a href="javascript:;" onclick="del('<?$u.id?>')" class="remove" title="删除"></a>
	</td>
</tr>
<? } ?>
</tbody></table>

<br/>
<input type="button" value="增加仓库" onclick="add()" />


<script>

function add()
{
	$.get('<?url('warehouse-nature')?>', function(jsn){
		_show_dialog(1, jsn);
		return ;
	});
}

function modify(warehouse_id)
{
	$.get('<?url('warehouse-nature/warehouse_id/USER_ID')?>'.replace('USER_ID',warehouse_id), function(jsn){
		_show_dialog(0, jsn);
		return ;
	});
}

function _show_dialog(type, jsn){
	if(!ajax_ok(jsn)) return ;
	show_dialog({
		title	: type ? '添加仓库' : '修改仓库',
		content	: jsn.message,
		ajaxform : function(jsn){
			if(jsn.method=='update'){
				$('tr[warehouse_id='+jsn.warehouse_id+']').replaceWith(jsn.html);
			}
			else{
				$('#list > tbody').append(jsn.html);
			}
		}
	});
}

function del(warehouse_id)
{
	if(confirm('确认删除?'))
	{
		$.get('<?url('warehouse-delete/warehouse_id/USER_ID')?>'.replace('USER_ID',warehouse_id), function(jsn){
			alert(jsn.message);
			location.reload();
		});
	}
}

</script>

<? include "FASHION/page_footer.phtml" ?>
